// pages/home/home.js
import Tx from "../../utils/qqmap-wx-jssdk1.2/qqmap-wx-jssdk";
import http from "../../utils/http"
var qqmapsdk = new Tx({
    key: 'AZLBZ-22X3K-7MKJ7-ANJ54-SH67F-2DFFN' // 必填
});
Page({

    /**
     * 页面的初始数据
     */
    data: {
        city: "",
        cinemaList: [],
        hotMovieList:[],
        imgUrls: ['../../assets/imgs/home/banner1.jpg', '../../assets/imgs/home/banner2.jpg', '../../assets/imgs/home/banner3.jpg'],
        indicatorDots: true,
        vertical: false,
        autoplay: true,
        interval: 2000,
        duration: 500,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },
    getLocation() {
        var _this = this;
        wx.getLocation({
            success(res) {
                console.log(res);
                qqmapsdk.reverseGeocoder({
                    location: `${res.latitude},${res.longitude}`,
                    success: function (res) {
                        console.log(res);
                        _this.setData({
                            city: res.result.ad_info.city
                        })
                    }
                });
                qqmapsdk.search({
                    keyword: "影院",
                    location: `${res.latitude},${res.longitude}`,
                    success: function (val) {
                        console.log(val);
                        val.data.forEach(el => {
                            qqmapsdk.calculateDistance({
                                from: `${res.latitude},${res.longitude}`,
                                to: `${el.location.lat},${el.location.lng}`,
                                success(result) {
                                    console.log(result);
                                    var dis = result.result.elements[0].distance / 1000 + "公里";
                                    console.log(dis)
                                }
                            })
                        })
                    }
                })
            }
        })
    },
    gethotMovie(){
        var _this = this;
        http.get("/api/douban/movie/in_theaters")
        .then(res=>{
            console.log(res);
            _this.setData({
                hotMovieList:res.data.data.list
            });
            console.log(this.data.hotMovieList)
        })
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        this.getLocation();
        this.gethotMovie();
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})